package impl;

import anaydis.sort.SorterType;

import java.util.Comparator;
import java.util.List;

public class AbstractQuickSorter extends AbstractSorter {


    protected AbstractQuickSorter(SorterType type) {
        super(type);
    }

    protected <T> int partition(Comparator<T> comparator, List<T> list, int left, int right) {
        int l = left, r = right;
        while (l < r) {
            while (!greater(comparator, list, l, right)) {
                l++;
                if (l == right) break;
            }
            while (!greater(comparator, list, right, r)) {
                r--;
                if (r == left) break;
            }
            if (l >= r) break;
            swap(list, l, r);
        }
        swap(list, l, right);
        return l;
    }
}

